package com.bus.admin.controller;


import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import com.bus.admin.bean.result.ResultPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bus.admin.bean.Feedback;
import com.bus.admin.bean.result.ResultPage;
import com.bus.admin.controller.model.ApiResultModel;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 反馈表 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2020-04-01
 */
@Controller
@RequestMapping("/bus/feedback")
public class FeedbackController extends BaseController{
     /** 主页面 */
    @RequestMapping("main.html")
    public String main(){
       return  "feedback/FeedbackMain";
    }
    /** 添加页面跳转
     * @return 返回页面
     */
    @RequestMapping(value = "/addFeedbackHtml")
    public String addFeedbackHtml( ){
             return "feedback/FeedbackAdd";
    }
    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "/editFeedbackHtml")
    public String editFeedbackHtml(Integer id ,Model model ){
           model.addAttribute("feedback",feedbackService.selectFeedbackByIdFeedback(id));
             return "feedback/FeedbackEdit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "/showFeedbackHtml")
    public String showFeedbackHtml(Integer id ,Model model ){
       Feedback feedback= feedbackService.selectFeedbackByIdFeedback(id);
       if(!StrUtil.isBlank(feedback.getWriteTime())){
           feedback.setWriteTime(DateUtil.formatDateTime(new Date(Long.parseLong(feedback.getWriteTime()))));
       }
           model.addAttribute("feedback",feedback);
             return "feedback/FeedbackShow";
    }


    /** 分页查询Feedback
     * @param page  页码
     * @param limit  查几条
     * @param feedback  前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "/findFeedbackByPage")
    @ResponseBody
    public ResultPage findFeedbackByPage(Integer page, Integer limit,Feedback feedback){
             return feedbackService.findFeedbackByPage(page,limit,feedback);
    }

    /** 添加Feedback
     * @param feedback  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/addFeedback")
    @ResponseBody
    public ApiResultModel saveFeedback(Feedback feedback  ){
             return feedbackService.addFeedback(feedback);
    }

    /** 编辑Feedback
     * @param feedback  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "/editFeedback")
    @ResponseBody
    public ApiResultModel editFeedback(Feedback feedback  ){
             return feedbackService.editFeedback(feedback);
    }



    /** 删除一条Feedback
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "/delFeedback")
    @ResponseBody
    public ApiResultModel delFeedback( Integer id  ){
             return feedbackService.delFeedback(id);
    }


}
